package com.galaxy.order.api;

import com.galaxy.common.core.domain.R;
import com.galaxy.order.domain.CheckStock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 商品服务降级处理
 */
@Component
public class RemoteDeviceFallbackFactory implements FallbackFactory<RemoteDeviceService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteDeviceFallbackFactory.class);

    @Override
    public RemoteDeviceService create(Throwable cause) {
        log.error("订单服务调用失败: {}", cause.getMessage());
        return new RemoteDeviceService() {
            @Override
            public R<Boolean> update(List<CheckStock> checkStockList) {
                return R.fail("订单服务调用失败");
            }

            @Override
            public R<String> getInfo(Long id) {
                return R.fail("订单服务调用失败");
            }
        };
    }
}
